//
//  ViewsListView.swift
//  SwiftUIDemo
//
//  Created by zuosong on 2019/12/1.
//  Copyright © 2019 Kael. All rights reserved.
//

import SwiftUI

struct ViewsListView: View {
    
    var viewNames = ["Text View","TextFiled View","SecureField","ButtonPageView","ImagePageView"]
    
    var body: some View {
        NavigationView{
            List(0..<viewNames.count) { item in
                
                NavigationLink(destination: self.jumpToNextView(item: item)) {
                    Text(self.viewNames[item]).bold()
                           .foregroundColor(.orange)
                           .font(.title)
                       }
            }.navigationBarTitle(Text("List"), displayMode: .large)
            .navigationBarTitle(Text("Views List"))
        }
        
    }
    
    func jumpToNextView(item : Int) -> AnyView {
        if item == 0 {
            return AnyView(
                TextPageView()
            )
        }
        if item == 1 {
            return AnyView(
                TextFiledPageView()
            )
        }
        if item == 2 {
            return AnyView(
                SecureFieldView()
            )
        }
        if item == 3 {
            return AnyView(
                ButtonPageView()
            )
        }
        if item == 4 {
            return AnyView(
                ImagePageView()
            )
        }
         
        return AnyView(
            TextFiledPageView()
        )
    }
}

struct ViewsListView_Previews: PreviewProvider {
    static var previews: some View {
        ViewsListView()
    }
}
